package cn.cuilan.common.core;

import cn.cuilan.common.entity.ProtocolMessage;
import io.netty.channel.ChannelHandlerContext;

/**
 * 自定义协议消息监听器
 *
 * @param <M> 私有协议消息类
 * @author zhang.yan
 */
public interface ProtocolMessageListener<M extends ProtocolMessage> {

    /**
     * Returns <code>true</code> if given message can be handled by {@link #onMessage(ChannelHandlerContext, ProtocolMessage)}.
     *
     * @param protocolMessage message to check. Not null.
     * @return true if message should be handled.
     */
    boolean applies(M protocolMessage);

    /**
     * Handles the message. If message should not be processed by any other handlers then this method should return <code>false</code>.
     *
     * @param ctx             current {@link ChannelHandlerContext}
     * @param protocolMessage received isoMessage. Not null.
     * @return true if message should be handled by subsequent message listeners
     */
    boolean onMessage(ChannelHandlerContext ctx, M protocolMessage);
}
